package com.wujilin.okra.fragment;

import static com.wujilin.okra.Okra.EXTRA_KEY_RESULT_ID;
import static com.wujilin.okra.Okra.T_KEY_RESULT;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.wujilin.okra.R;
import com.wujilin.okra.database.Sql;

public class KeyResultDeleteFragment extends KeyResultDialogFragment {

	@Override
	public void onClickPositiveButton(DialogInterface dialog, Bundle args) {
		long id = args.getLong(EXTRA_KEY_RESULT_ID);
		Sql.delete(T_KEY_RESULT, id);
	}

	@Override
	public void onCreateDialog(Builder builder) {
		View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_confirm_delete, null);
		TextView confirmText = (TextView) view.findViewById(R.id.confirm_delete);
		confirmText.setText(R.string.confirm_delete_key_result);
		
		builder.setView(view).setTitle(R.string.delete);
	}

	public static KeyResultDeleteFragment netInstance(long id) {
		Bundle args = new Bundle();
		args.putLong(EXTRA_KEY_RESULT_ID, id);
		
		KeyResultDeleteFragment fragment = new KeyResultDeleteFragment();
		fragment.setArguments(args);
		
		return fragment;
	}
}
